<%@ page isELIgnored="false" %><%--isELIgnored=true禁用EL表达式--%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- JSTL标签库是一个JSP标签的集合，封装了许多jsp应用程序通用的核心功能-->
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/layui-v2.6.13/layui/css/layui.css"/>
    <script src="${pageContext.request.contextPath}/js/jquery.min-2.1.1.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/layui-v2.6.13/layui/layui.js"></script>
    <style>
        .layui-row{
            margin-bottom: 30px;
        }
        .layui-form{
            margin-left: 20px;
            margin-top: 20px;
        }
        #d1{
            margin-left: 20px;
            margin-top: 20px;
        }
    </style>
</head>
<body>

<form class="layui-form" action="http://localhost:8080/shopping/order/queryAllOrder">
    <div class="layui-row">
        <!-- layui-input-block：是一个表单元素占一行，竖着，以例表的形式排列。
            layui-input-inline：多个表单控件占一行，横着，一行可以放置多个表单元素。 -->
        <div class="layui-input-inline">
            <input type="text" name="orderNo" placeholder="请输入查询订单号"  class="layui-input" value="${order.orderNo}">
        </div>

        <div class="layui-input-inline">
            <select name="orderStatus">
                <option value="">订单状态</option>
                <option <c:if test="${order.orderStatus == 1}"> selected=true </c:if> value="1">待付款</option>
                <option <c:if test="${order.orderStatus == 2}"> selected=true </c:if> value="2">待发货</option>
                <option <c:if test="${order.orderStatus == 3}"> selected=true </c:if> value="3">已发货</option>
                <option <c:if test="${order.orderStatus == 4}"> selected=true </c:if> value="4">已签收</option>
                <option <c:if test="${order.orderStatus == 5}"> selected=true </c:if> value="5">退款中</option>
                <option <c:if test="${order.orderStatus == 6}"> selected=true </c:if> value="6">已退款</option>
                <option <c:if test="${order.orderStatus == 7}"> selected=true </c:if> value="7">交易结束</option>
            </select>
        </div>
        <!-- layui-btn 把标签作为按钮
            layui-btn-sm 小型按钮 -->
        <button class="layui-btn">查询</button>
    </div>
</form>
<div id="d1">
    <button class="layui-btn" type="button" onclick="sendGoods()">一键发货</button>
    <!-- <table class="layui-table" lay-even lay-skin="nob">
            无边框表格（内部结构参见右侧目录“常规用法”）
        </table> -->
    <table class="layui-table">
        <!-- colgroup中可以使用col来定义表格单元格宽度， -->
        <colgroup>
            <col width="50">
            <col width="200">
            <col width="200">
            <col width="200">
            <col width="200">
            <col width="200">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th><input type="checkbox" name="allsel" lay-skin="primary" onclick="checkAll()"></th>
            <th>订单号</th>
            <th>用户ID</th>
            <th>用户名</th>
            <th>交易金额</th>
            <th>交易时间</th>
            <th>订单状态</th>
            <th>订单详情</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${list}" var="order">
            <tr>
                <td><input type="checkbox" name="orderStatus" lay-skin="primary" value="${order.orderNo}" ></td>
                <td>${order.orderNo}</td>
                <td>${order.uId}</td>
                <td>${order.uName}</td>
                <td>${order.orderMoney}</td>
                <td><f:formatDate value="${order.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/></td>
                <td>
                    <c:if test="${order.orderStatus == 1}">待付款</c:if>
                    <c:if test="${order.orderStatus == 2}">待发货</c:if>
                    <c:if test="${order.orderStatus == 3}">已发货</c:if>
                    <c:if test="${order.orderStatus == 4}">已签收</c:if>
                    <c:if test="${order.orderStatus == 5}">退款中</c:if>
                    <c:if test="${order.orderStatus == 6}">已退款</c:if>
                    <c:if test="${order.orderStatus == 7}">交易结束</c:if>
                </td>
                <td><a onclick="orderGoods('${order.orderNo}')">查看</a></td>
            </tr>
        </c:forEach>
        </tbody>
    </table>
    <div id="test1" style="text-align: center;"></div>
    <div style="text-align: center;">
        <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="queryByPageNO(1,${totalPage})">首页</button>
        <button class="layui-btn" onclick = "queryByPageNO(${pageNo-1},${totalPage})">上一页</button>
        <span class = "layui-font-16">${pageNo} / ${totalPage}页</span>
        <button class="layui-btn" onclick = "queryByPageNO(${pageNo+1},${totalPage})">下一页</button>
        <button class="layui-btn layui-btn-sm layui-btn-primary" onclick="queryByPageNO(${totalPage},${totalPage})">尾页</button>
    </div>
</div>
</body>
<script>
    function orderGoods(orderNo){
        window.location.href = "http://localhost:8080/shopping/orderGoods/queryOrderGoods?orderNo="+orderNo;

    }
    function sendGoods(){
// var arr = [];	//声明一个数组用来存放遍历出来的checkbox value值
        // $("input[name='productState']:checked").each(function(i) {	//遍历
        //     arr.push("productId=" + $(this).val());	//将我们遍历出来的值push到数组中
        //     //最后可以提交arr就可以实现将我们选中的checkbox的value值提交
        //
        // });
        var userList = new Array();
        $("input[name='orderStatus']:checked").each(function(i){
            var i = $(this).val();
            userList.push(i);
        });
        console.info(userList);
        $.ajax({
            url:"http://localhost:8080/shopping/order/sendGoods",
            data:{ids : userList},
            type:"get",
            dataType:"json",
            success(obj){
                if(obj == "1"){
                    alert("发货成功");
                }else {
                    alert("您选择的不是待发货的商品！");
                }
                window.location.reload();
            }
        });
    }
    function queryByPageNO(pageNo,totalPage){
        if(pageNo <= totalPage){
            //查询条件
            var params = $("form").serialize();
            if(pageNo < 1) pageNo = 1;
            window.location.href = "http://localhost:8080/shopping/order/queryAllOrder?"+params+"&pageNo="+pageNo;
        }
    }
    // function checkAll(){
    //     $("input[name='orderStatus']:not(:checked)").each(function() {
    //         this.checked = true;
    //     });
    // }
    function checkAll(){
        var obj = $("input[name='allsel']").prop("checked");
        if (obj === true){
            $("input[name='orderStatus']:not(:checked)").each(function() {
                this.checked = true;
            });
        }
        if (obj === false){
            $("input[name='orderStatus']:checked").each(function() {
                this.checked = false;
            });
        }
    }
</script>
</html>